/*
Copyright (C) 1997-2001 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/
/* Modifications
   Copyright 2003-2004 Bytonic Software
   Copyright 2010 Google Inc.
*/
package com.googlecode.playnquake.core.client;

import com.googlecode.playnquake.core.common.Constants;
import com.googlecode.playnquake.core.game.Model;
import com.googlecode.playnquake.core.game.UserCommand;
import com.googlecode.playnquake.core.render.Image;
import com.googlecode.playnquake.core.sound.*;


public class ClientState {

	public ClientState() {
		for (int n = 0; n < Constants.CMD_BACKUP; n++)
			cmds[n] = new UserCommand();
		for (int i = 0; i < frames.length; i++) {
			frames[i] = new FrameData();
		}

		for (int n = 0; n < Constants.MAX_CONFIGSTRINGS; n++)
			configstrings[n] = new String();
			
		for (int n=0; n < Constants.MAX_CLIENTS; n++)
			clientinfo[n] = new ClientInfo();
	}
	//
	//	   the client_state_t structure is wiped completely at every
	//	   server map change
	//
	int timeoutcount;

	int timedemo_frames;
	int timedemo_start;

	public boolean refresh_prepped; // false if on new level or new ref dll
	public boolean sound_prepped; // ambient sounds can start
	boolean force_refdef; // vid has changed, so we can't use a paused refdef

	int parse_entities; // index (not anded off) into cl_parse_entities[]

	UserCommand cmd = new UserCommand();
	UserCommand cmds[] = new UserCommand[Constants.CMD_BACKUP]; // each mesage will send several old cmds

	int cmd_time[] = new int[Constants.CMD_BACKUP]; // time sent, for calculating pings
	short predicted_origins[][] = new short[Constants.CMD_BACKUP][3]; // for debug comparing against server

	float predicted_step; // for stair up smoothing
	int predicted_step_time;

	float[] predicted_origin ={0,0,0}; // generated by CL_PredictMovement
	float[] predicted_angles={0,0,0};
	float[] prediction_error={0,0,0};

	public FrameData frame = new FrameData(); // received from server
	int surpressCount; // number of messages rate supressed
	FrameData frames[] = new FrameData[Constants.UPDATE_BACKUP];

	// the client maintains its own idea of view angles, which are
	// sent to the server each frame.  It is cleared to 0 upon entering each level.
	// the server sends a delta each frame which is added to the locally
	// tracked view angles to account for standing on rotating objects,
	// and teleport direction changes
	public float[] viewangles = { 0, 0, 0 };

	public int time; // this is the time value that the client
	// is rendering at.  always <= cls.realtime
	float lerpfrac; // between oldframe and frame

	RendererState refdef = new RendererState();

	float[] v_forward = { 0, 0, 0 };
	float[] v_right = { 0, 0, 0 };
	float[] v_up = { 0, 0, 0 }; // set when refdef.angles is set

	//
	// transient data from server
	//

	String layout = ""; // general 2D overlay
	int inventory[] = new int[Constants.MAX_ITEMS];

	int cinematictime; // cls.realtime for first cinematic frame
	int cinematicframe;
	byte cinematicpalette[] = new byte[768];
	boolean cinematicpalette_active;

	//
	// server state information
	//
	boolean attractloop; // running the attract loop, any key will menu
	int servercount; // server identification for prespawns
	String gamedir ="";
	public int playernum;

	public String configstrings[] = new String[Constants.MAX_CONFIGSTRINGS];

	//
	// locally derived information from server state
	//
	com.googlecode.playnquake.core.render.Model model_draw[] = 
	    new com.googlecode.playnquake.core.render.Model[Constants.MAX_MODELS];
	Model model_clip[] = new Model[Constants.MAX_MODELS];

	public Sfx sound_precache[] = new Sfx[Constants.MAX_SOUNDS];
	Image image_precache[] = new Image[Constants.MAX_IMAGES];

	ClientInfo clientinfo[] = new ClientInfo[Constants.MAX_CLIENTS];
	ClientInfo baseclientinfo = new ClientInfo();

}
